'use strict';

module.exports = app => {
    const { Sequelize, model } = app

    const Model = model.define('booking', {
        id:{
            type: Sequelize.STRING.BINARY,
            defaultValue: Sequelize.UUIDV1,
            primaryKey: true
        },
        formId:{
            type: Sequelize.STRING(50),
        },
        openId:{
            type: Sequelize.STRING(50),
        },
        mobile:{
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        carNum:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        carType: {
            type: Sequelize.INTEGER(1),
            allowNull: false,
        },
        carMac: {
            type: Sequelize.STRING(20),
            allowNull: false,
        },
        bookDate:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        bookTime:{
            type: Sequelize.STRING(10),
            allowNull: false,
        },
        source:{
            type: Sequelize.INTEGER(2),
            defaultValue: 0,
            allowNull: false,
        },
        rejectMsg:{
            type: Sequelize.STRING(100),
        },
        status:{
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
        payFlag:{
            type: Sequelize.INTEGER(1),
            defaultValue: 0,
            allowNull: false,
        },
    }, {
        freezeTableName: true,
        tableName: 'tb_booking',
    })

    Model.associate = function() {
        model.Booking.belongsTo(model.Corp)
        model.Booking.belongsTo(model.MinaPartner)
        model.Corp.hasMany(model.Booking)
        model.MinaPartner.hasMany(model.Booking)
    }

    return Model
}